<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta property="og:title" content="23年3月技术杂记" />
<meta property="og:description" content="WxDatViewer
指定端口
1 nmap -p 21,22,25,80,445,3306,1521,8080,8888 扫描端口和版本
1 nmap -sV 扫描操作系统
1 nmap -O 127.0.0.1 在Windows系统中，程序默认是要有窗口显示的，而且运行中的任务一般还要在任务栏上有所反应，这样便于切换操作。不过有些时候我们可能只想它默默地在后台运行，那么该如何隐藏程序的运行界面呢？
vbs方式隐藏 1 2 3 4 Dim WShell Set WShell = CreateObject(&#34;WScript.Shell&#34;) WShell.Run &#34;background.exe&#34;, 0 Set WShell = Nothing 注册为服务 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 uname -a # 查看内核/操作系统/CPU信息 head -n 1 /etc/issue # 查看操作系统版本 hostname # 查看计算机名 env # 查看环境变量 free -m # 查看内存使用量和交换区使用量 df -h # 查看各分区使用情况 du -sh &lt;目录名&gt; # 查看指定目录的大小 grep MemTotal /proc/meminfo # 查看内存总量 grep MemFree /proc/meminfo # 查看空闲内存量 uptime # 查看系统运行时间、用户数、负载 cat /proc/loadavg # 查看系统负载 route -n # 查看路由表 netstat -lntp # 查看所有监听端口 netstat -antp # 查看所有已经建立的连接 netstat -s # 查看网络统计信息 ps -ef # 查看所有进程 WSL1 代理 由于 Linux 子系统和 Windows 共享了网络端口，所以访问 Windows 的代理非常简单。例如 Windows 的代理客户端监听了 8000 端口，那么只需要在 Linux 子系统中执行如下命令，就可以让当前 session 中的请求通过代理访问互联网。" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://wuju-i.gitee.io/post/20230304-nmap/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2023-03-04T00:00:00+00:00" />
<meta property="article:modified_time" content="2023-03-04T00:00:00+00:00" />

  <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="23年3月技术杂记"/>
<meta name="twitter:description" content="WxDatViewer
指定端口
1 nmap -p 21,22,25,80,445,3306,1521,8080,8888 扫描端口和版本
1 nmap -sV 扫描操作系统
1 nmap -O 127.0.0.1 在Windows系统中，程序默认是要有窗口显示的，而且运行中的任务一般还要在任务栏上有所反应，这样便于切换操作。不过有些时候我们可能只想它默默地在后台运行，那么该如何隐藏程序的运行界面呢？
vbs方式隐藏 1 2 3 4 Dim WShell Set WShell = CreateObject(&#34;WScript.Shell&#34;) WShell.Run &#34;background.exe&#34;, 0 Set WShell = Nothing 注册为服务 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 uname -a # 查看内核/操作系统/CPU信息 head -n 1 /etc/issue # 查看操作系统版本 hostname # 查看计算机名 env # 查看环境变量 free -m # 查看内存使用量和交换区使用量 df -h # 查看各分区使用情况 du -sh &lt;目录名&gt; # 查看指定目录的大小 grep MemTotal /proc/meminfo # 查看内存总量 grep MemFree /proc/meminfo # 查看空闲内存量 uptime # 查看系统运行时间、用户数、负载 cat /proc/loadavg # 查看系统负载 route -n # 查看路由表 netstat -lntp # 查看所有监听端口 netstat -antp # 查看所有已经建立的连接 netstat -s # 查看网络统计信息 ps -ef # 查看所有进程 WSL1 代理 由于 Linux 子系统和 Windows 共享了网络端口，所以访问 Windows 的代理非常简单。例如 Windows 的代理客户端监听了 8000 端口，那么只需要在 Linux 子系统中执行如下命令，就可以让当前 session 中的请求通过代理访问互联网。"/>

  
  <meta name="theme-color" media="(prefers-color-scheme: light)" content="#ffffff">
  <meta name="theme-color" media="(prefers-color-scheme: dark)" content="#262d33">
  <title>
    
    橘子的博客 - 23年3月技术杂记
    
  </title>
  
  <link rel="shortcut icon" href="g.png" type="image/x-icon" />
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&display=swap"
    rel="stylesheet">
  
  
  
  <link rel="stylesheet" href="/minima.1714031344.css">

  
  
  <script defer type="text/javascript" src="/minima.1714031344.js"></script>
</head>
<script>
  
  let theme_2b_used = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';

  try {
    if (!('theme' in localStorage)) {
      const default_theme = '';
      
      
      if (default_theme === 'dark' || default_theme === 'light') {
        theme_2b_used = default_theme;
      }

      
      localStorage.theme = theme_2b_used;
    }
    
    document.querySelector('html').classList.add(localStorage.theme);
  } catch (e) {
    console.error(e);
  }
</script>


<body class=" sm:mx-5 sm:my-0">
  <header class="flex justify-between items-center mb-6 sm:my-3">
  <div class="flex items-center">
    
    <div id="theme-switcher" class="text-4xl cursor-pointer">🌑</div>
  </div>
  <nav class="flex items-center
    whitespace-nowrap overflow-x-auto overflow-y-hidden">
    
    <a class="ml-5" href="/">首页</a>
    
    <a class="ml-5" href="/categories">分类</a>
    
    <a class="ml-5" href="/log">日记</a>
    
    <a class="ml-5" href="/about">关于</a>
    
  </nav>
</header>
  
  

<h1 class="mt-6 mb-6">23年3月技术杂记</h1>
<div class="mb-3 text-xs flex justify-between sm:flex-col">
	<div>
	
		Posted at &mdash; 23年 3月4日
	
		
	</div>
	
</div>
<main>
	<p></p>
	<article class="md">
		<p>WxDatViewer</p>
<p>指定端口</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nmap -p 21,22,25,80,445,3306,1521,8080,8888 
</span></span></code></pre></td></tr></table>
</div>
</div><p>扫描端口和版本</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nmap -sV 
</span></span></code></pre></td></tr></table>
</div>
</div><p>扫描操作系统</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">nmap -O 127.0.0.1
</span></span></code></pre></td></tr></table>
</div>
</div><p>在Windows系统中，程序默认是要有窗口显示的，而且运行中的任务一般还要在任务栏上有所反应，这样便于切换操作。不过有些时候我们可能只想它默默地在后台运行，那么该如何隐藏程序的运行界面呢？</p>
<ol>
<li>vbs方式隐藏</li>
</ol>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">Dim WShell
</span></span><span class="line"><span class="cl">Set <span class="nv">WShell</span> <span class="o">=</span> CreateObject<span class="o">(</span><span class="s2">&#34;WScript.Shell&#34;</span><span class="o">)</span>
</span></span><span class="line"><span class="cl">WShell.Run <span class="s2">&#34;background.exe&#34;</span>, <span class="m">0</span>
</span></span><span class="line"><span class="cl">Set <span class="nv">WShell</span> <span class="o">=</span> Nothing
</span></span></code></pre></td></tr></table>
</div>
</div><ol start="2">
<li>注册为服务</li>
</ol>
<hr>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">uname -a               <span class="c1"># 查看内核/操作系统/CPU信息</span>
</span></span><span class="line"><span class="cl">head -n <span class="m">1</span> /etc/issue   <span class="c1"># 查看操作系统版本</span>
</span></span><span class="line"><span class="cl">hostname               <span class="c1"># 查看计算机名</span>
</span></span><span class="line"><span class="cl">env                    <span class="c1"># 查看环境变量</span>
</span></span><span class="line"><span class="cl">free -m                <span class="c1"># 查看内存使用量和交换区使用量</span>
</span></span><span class="line"><span class="cl">df -h                  <span class="c1"># 查看各分区使用情况</span>
</span></span><span class="line"><span class="cl">du -sh &lt;目录名&gt;        <span class="c1"># 查看指定目录的大小</span>
</span></span><span class="line"><span class="cl">grep MemTotal /proc/meminfo   <span class="c1"># 查看内存总量</span>
</span></span><span class="line"><span class="cl">grep MemFree /proc/meminfo    <span class="c1"># 查看空闲内存量</span>
</span></span><span class="line"><span class="cl">uptime                 <span class="c1"># 查看系统运行时间、用户数、负载</span>
</span></span><span class="line"><span class="cl">cat /proc/loadavg      <span class="c1"># 查看系统负载</span>
</span></span><span class="line"><span class="cl">route -n               <span class="c1"># 查看路由表</span>
</span></span><span class="line"><span class="cl">netstat -lntp          <span class="c1"># 查看所有监听端口</span>
</span></span><span class="line"><span class="cl">netstat -antp          <span class="c1"># 查看所有已经建立的连接</span>
</span></span><span class="line"><span class="cl">netstat -s             <span class="c1"># 查看网络统计信息</span>
</span></span><span class="line"><span class="cl">ps -ef                 <span class="c1"># 查看所有进程</span>
</span></span></code></pre></td></tr></table>
</div>
</div><hr>
<p>WSL1 代理
由于 Linux 子系统和 Windows 共享了网络端口，所以访问 Windows 的代理非常简单。例如 Windows 的代理客户端监听了 8000 端口，那么只需要在 Linux 子系统中执行如下命令，就可以让当前 session 中的请求通过代理访问互联网。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">ALL_PROXY</span><span class="o">=</span><span class="s2">&#34;http://127.0.0.1:8000&#34;</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>WSL2 代理
有两个关键步骤：</p>
<p>WSL2 中配置的代理要指向 Windows 的 IP；
Windows 上的代理客户端需要允许来自本地局域网的请求；
由于 Linux 子系统也是通过 Windows 访问网络，所以 Linux 子系统中的网关指向的是 Windows，DNS 服务器指向的也是 Windows，基于这两个特性，我们可以将 Windows 的 IP 读取出来。
例如，我使用的是 Debian 子系统，通过 cat /etc/resolv.conf 查看 DNS 服务器 IP。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:</span>
</span></span><span class="line"><span class="cl"><span class="c1"># [network]</span>
</span></span><span class="line"><span class="cl"><span class="c1"># generateResolvConf = false</span>
</span></span><span class="line"><span class="cl">nameserver 172.27.144.1
</span></span></code></pre></td></tr></table>
</div>
</div><p>可以看到 DNS 服务器是  172.19.80.1，通过环境变量  ALL_PROXY  配置代理</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">export</span> <span class="nv">ALL_PROXY</span><span class="o">=</span><span class="s2">&#34;http://172.25.144.1:37507&#34;</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>37507 是 Windows 上运行的代理客户端的端口，记得要在 Windows 代理客户端上配置允许本地局域网请求。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-php" data-lang="php"><span class="line"><span class="cl"><span class="o">&lt;?</span><span class="nx">php</span>
</span></span><span class="line"><span class="cl"><span class="c1">// 日志组件  
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="k">require_once</span> <span class="no">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;./vendor/autoload.php&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">use</span> <span class="nx">Monolog\Logger</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="k">use</span> <span class="nx">Monolog\Handler\StreamHandler</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nv">$log</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Logger</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="nv">$log</span><span class="o">-&gt;</span><span class="na">pushHandler</span><span class="p">(</span><span class="k">new</span> <span class="nx">StreamHandler</span><span class="p">(</span><span class="s1">&#39;./logs/&#39;</span> <span class="o">.</span> <span class="nx">date</span><span class="p">(</span><span class="s1">&#39;Ymd&#39;</span><span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;.log&#39;</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">// add records to the log
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="k">for</span> <span class="p">(</span><span class="nv">$i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="nv">$i</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nv">$i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span> 
</span></span><span class="line"><span class="cl">  <span class="nv">$log</span><span class="o">-&gt;</span><span class="na">warning</span><span class="p">(</span><span class="s1">&#39;Foo &#39;</span> <span class="o">.</span> <span class="nv">$i</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="c1">// Node.js 内存锁
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>
</span></span><span class="line"><span class="cl"><span class="kr">const</span> <span class="nx">performance</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;perf_hooks&#39;</span><span class="p">).</span><span class="nx">performance</span>
</span></span><span class="line"><span class="cl"><span class="kr">const</span> <span class="nx">LockList</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Map</span><span class="p">();</span>
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">uid</span> <span class="o">=</span> <span class="s1">&#39;123&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="kr">const</span> <span class="nx">Seconds</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">r</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">if</span> <span class="p">(</span><span class="nx">r</span> <span class="o">=</span> <span class="nx">LockList</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">uid</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="kd">let</span> <span class="nx">time_now</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span><span class="p">((</span><span class="nx">performance</span><span class="p">.</span><span class="nx">timeOrigin</span> <span class="o">+</span> <span class="nx">performance</span><span class="p">.</span><span class="nx">now</span><span class="p">())</span> <span class="o">/</span> <span class="mi">1000</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">  <span class="kd">let</span> <span class="nx">slepp_seconds</span> <span class="o">=</span> <span class="p">(</span><span class="nx">time_now</span> <span class="o">-</span> <span class="nx">r</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">  <span class="k">if</span> <span class="p">(</span><span class="nx">slepp_seconds</span> <span class="o">&gt;</span> <span class="nx">Seconds</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;已经过期，可以开始操作&#39;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// next();
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`请等待 </span><span class="si">${</span><span class="nx">Seconds</span> <span class="o">-</span> <span class="nx">slepp_seconds</span><span class="si">}</span><span class="sb"> 秒`</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="c1">// 回复 - 请等待 Seconds - slepp_seconds 秒
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="c1">// return false;
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>  <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">r</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="c1">// 存入时间戳(最快方式)
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>  <span class="nx">LockList</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">uid</span><span class="p">,</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span><span class="p">((</span><span class="nx">performance</span><span class="p">.</span><span class="nx">timeOrigin</span> <span class="o">+</span> <span class="nx">performance</span><span class="p">.</span><span class="nx">now</span><span class="p">())</span> <span class="o">/</span> <span class="mi">1000</span><span class="p">)</span> <span class="p">);</span>
</span></span><span class="line"><span class="cl">  <span class="c1">// next();
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="c1">// Node.JS 并发任务
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="kr">const</span> <span class="nx">taskCount</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">function</span> <span class="nx">sleep</span><span class="p">(</span><span class="nx">ms</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">return</span> <span class="k">new</span> <span class="nb">Promise</span><span class="p">(</span><span class="nx">resolve</span><span class="p">=&gt;</span><span class="nx">setTimeout</span><span class="p">(</span><span class="nx">resolve</span><span class="p">,</span> <span class="nx">ms</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">function</span> <span class="nx">runTask</span><span class="p">(</span><span class="nx">index</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">return</span> <span class="k">new</span> <span class="nb">Promise</span><span class="p">(</span><span class="kr">async</span> <span class="nx">resolve</span><span class="p">=&gt;{</span>
</span></span><span class="line"><span class="cl">    <span class="kr">await</span> <span class="nx">sleep</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="nx">resolve</span><span class="p">(</span> <span class="s1">&#39;任务-&gt; &#39;</span> <span class="o">+</span> <span class="nx">index</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">  <span class="p">});</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">r</span> <span class="o">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">  <span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">7</span><span class="p">,</span><span class="mi">8</span>
</span></span><span class="line"><span class="cl"><span class="p">].</span><span class="nx">reverse</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">totalPage</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span> <span class="o">/</span> <span class="nx">taskCount</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">(</span><span class="kr">async</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">totalPage</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kd">let</span> <span class="nx">TaskList</span> <span class="o">=</span> <span class="p">[];</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="k">break</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">||</span> <span class="p">(</span><span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="nx">totalPage</span><span class="p">)</span> <span class="p">{}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="kr">await</span> <span class="nx">sleep</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`任务序号： </span><span class="si">${</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="sb"> 开始`</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">index</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">index</span> <span class="o">&lt;</span> <span class="nx">taskCount</span><span class="p">;</span> <span class="nx">index</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="kd">let</span> <span class="nx">t</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">      <span class="k">if</span> <span class="p">((</span><span class="nx">t</span> <span class="o">=</span> <span class="nx">r</span><span class="p">.</span><span class="nx">pop</span><span class="p">())</span><span class="o">!=</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="c1">// console.log(t);
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="c1">// 执行任务
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="nx">TaskList</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">runTask</span><span class="p">(</span><span class="nx">t</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="nb">Promise</span><span class="p">.</span><span class="nx">all</span><span class="p">(</span><span class="nx">TaskList</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="nx">data</span> <span class="p">=&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">});</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}())</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-typescript" data-lang="typescript"><span class="line"><span class="cl"><span class="c1">// Deno 并发任务
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="kr">const</span> <span class="nx">taskCount</span>:<span class="kt">number</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">function</span> <span class="nx">sleep</span><span class="p">(</span><span class="nx">ms</span>:<span class="kt">number</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">return</span> <span class="k">new</span> <span class="nx">Promise</span><span class="p">(</span><span class="nx">resolve</span><span class="o">=&gt;</span><span class="nx">setTimeout</span><span class="p">(</span><span class="nx">resolve</span><span class="p">,</span> <span class="nx">ms</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">function</span> <span class="nx">runTask</span><span class="p">(</span><span class="nx">index</span>:<span class="kt">string</span> <span class="o">|</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">return</span> <span class="k">new</span> <span class="nx">Promise</span><span class="p">(</span><span class="kr">async</span> <span class="nx">resolve</span><span class="o">=&gt;</span><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">await</span> <span class="nx">sleep</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="kr">const</span> <span class="nx">response</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">fetch</span><span class="p">(</span><span class="k">new</span> <span class="nx">URL</span><span class="p">(</span><span class="s1">&#39;http://www.baidu.com&#39;</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">    <span class="kr">const</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">response</span><span class="p">.</span><span class="nx">text</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">    <span class="nx">resolve</span><span class="p">(</span><span class="s1">&#39;任务-&gt; &#39;</span> <span class="o">+</span> <span class="nx">index</span> <span class="o">+</span> <span class="s1">&#39; 完成&#39;</span> <span class="o">+</span> <span class="nx">data</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="p">});</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">r</span> : <span class="kt">string</span><span class="p">[]</span> <span class="o">|</span> <span class="kc">undefined</span><span class="p">[]</span> <span class="o">=</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">  <span class="s1">&#39;1&#39;</span><span class="p">,</span><span class="s1">&#39;2&#39;</span><span class="p">,</span><span class="s1">&#39;3&#39;</span><span class="p">,</span><span class="s1">&#39;4&#39;</span><span class="p">].</span><span class="nx">reverse</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kd">let</span> <span class="nx">totalPage</span>:<span class="kt">number</span> <span class="o">=</span> <span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span> <span class="o">/</span> <span class="nx">taskCount</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">(</span><span class="kr">async</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">totalPage</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kd">let</span> <span class="nx">TaskList</span>:<span class="kt">Promise</span><span class="p">&lt;</span><span class="nt">unknown</span><span class="p">&gt;[]</span> <span class="o">=</span> <span class="p">[];</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">r</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="k">break</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">||</span> <span class="p">(</span><span class="nx">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="nx">totalPage</span><span class="p">)</span> <span class="p">{}</span> <span class="k">else</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="k">await</span> <span class="nx">sleep</span><span class="p">(</span><span class="mi">5000</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="sb">`任务序号： </span><span class="si">${</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="si">}</span><span class="sb"> 开始`</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">index</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">index</span> <span class="o">&lt;</span> <span class="nx">taskCount</span><span class="p">;</span> <span class="nx">index</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="kd">let</span> <span class="nx">t</span>:<span class="kt">string</span> <span class="o">|</span> <span class="kc">undefined</span> <span class="o">=</span> <span class="nx">r</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
</span></span><span class="line"><span class="cl">      <span class="k">if</span> <span class="p">(</span><span class="nx">t</span> <span class="o">!=</span> <span class="kc">undefined</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="c1">// 执行任务
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>        <span class="nx">TaskList</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">runTask</span><span class="p">(</span><span class="nx">t</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">Promise</span><span class="p">.</span><span class="nx">all</span><span class="p">(</span><span class="nx">TaskList</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="nx">data</span> <span class="o">=&gt;</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">});</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}())</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="k">load</span><span class="w"> </span><span class="k">data</span><span class="w"> </span><span class="k">local</span><span class="w"> </span><span class="n">infile</span><span class="w"> </span><span class="s2">&#34;course.txt&#34;</span><span class="w"> </span><span class="k">into</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">course</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">fields</span><span class="w"> </span><span class="n">terminated</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="s1">&#39;,&#39;</span><span class="w"> </span><span class="n">lines</span><span class="w"> </span><span class="n">terminated</span><span class="w"> </span><span class="k">by</span><span class="s1">&#39;\r\n&#39;</span><span class="p">;</span><span class="w">
</span></span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-nginx" data-lang="nginx"><span class="line"><span class="cl"><span class="k">http</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kn">charset</span>                <span class="s">utf-8</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">sendfile</span>               <span class="no">on</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">tcp_nopush</span>             <span class="no">on</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">tcp_nodelay</span>            <span class="no">on</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">server_tokens</span>          <span class="no">off</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">log_not_found</span>          <span class="no">off</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">types_hash_max_size</span>    <span class="mi">2048</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">types_hash_bucket_size</span> <span class="mi">64</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">client_max_body_size</span>   <span class="s">16M</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># MIME
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="kn">include</span>                <span class="s">mime.types</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">default_type</span>           <span class="s">application/octet-stream</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1"># Logging
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="kn">access_log</span>             <span class="no">off</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">error_log</span>              <span class="s">/dev/null</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="tar">tar</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar xvf FileName.tar                 # 解包
tar cvf FileName.tar DirName         # 打包TEXT
</code></pre><h2 id="gz">.gz</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">gunzip FileName.gz                   # 解压1
gzip -d FileName.gz                  # 解压2
gzip FileName                        # 压缩TEXT
</code></pre><h2 id="targz-和-tgz">.tar.gz 和 .tgz</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar zxvf FileName.tar.gz             # 解压
tar zcvf FileName.tar.gz DirName     # 压缩TEXT
</code></pre><h2 id="tarxz">.tar.xz</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar xvJf FileName.tar.xz             # 解压
tar cvJf FileName.tar.xz DirName     # 压缩TEXT
</code></pre><h2 id="bz2">.bz2</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">bzip2 -d FileName.bz2                # 解压1
bunzip2 FileName.bz2                 # 解压2
bzip2 -z FileName                    # 压缩TEXT
</code></pre><h2 id="tarbz2">.tar.bz2</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar jxvf FileName.tar.bz2            # 解压
tar jcvf FileName.tar.bz2 DirName    # 压缩TEXT
</code></pre><h2 id="bz">.bz</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">bzip2 -d FileName.bz                 # 解压1
bunzip2 FileName.bz                  # 解压2
bzip2 -z FileName                    # 压缩TEXT
</code></pre><h2 id="tarbz">.tar.bz</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar axvf FileName.tar.bz             # 解压
tar acvf FileName.tar.bz DirName     # 压缩TEXT
</code></pre><h2 id="z">.Z</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">uncompress FileName.Z                # 解压
compress FileName                    # 压缩TEXT
</code></pre><h2 id="tarz">.tar.Z</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">tar Zxvf FileName.tar.Z              # 解压
tar Zcvf FileName.tar.Z DirName      # 压缩TEXT
</code></pre><h2 id="zip">.zip</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">unzip FileName.zip                   # 解压
zip FileName.zip DirName             # 压缩TEXT
</code></pre><h2 id="rar">.rar</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">rar x FileName.rar                  # 解压
rar a FileName.rar DirName          # 压缩TEXT
</code></pre><h2 id="deb">.deb</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">ar p FileName.deb data.tar.gz | tar zxf -       # 解压
TEXT
</code></pre><h2 id="rpm">.rpm</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">rpm2cpio FileName.rpm | cpio -div   # 解包
TEXT
</code></pre><h2 id="lha">.lha</h2>
<pre tabindex="0"><code class="language-none" data-lang="none">lha -e FileName.lha                 # 解压
lha -a FileName.lha FileName        # 压缩TEXT
</code></pre><h2 id="sex">sEx</h2>
<p><code>sEx</code> 调用相关程序，实现压缩解压这些文件，本身并无压缩、解压功能：</p>
<ul>
<li><code>.tar</code></li>
<li><code>.tgz</code></li>
<li><code>.tar.gz</code></li>
<li><code>.tar.Z</code></li>
<li><code>.tar.bz</code></li>
<li><code>.tar.bz2</code></li>
<li><code>.zip</code></li>
<li><code>.cpio</code></li>
<li><code>.rpm</code></li>
<li><code>.deb</code></li>
<li><code>.slp</code></li>
<li><code>.arj</code></li>
<li><code>.rar</code></li>
<li><code>.ace</code></li>
<li><code>.lha</code></li>
<li><code>.lzh</code></li>
<li><code>.lzx</code></li>
<li><code>.lzs</code></li>
<li><code>.arc</code></li>
<li><code>.sda</code></li>
<li><code>.sfx</code></li>
<li><code>.lnx</code></li>
<li><code>.zoo</code></li>
<li><code>.cab</code></li>
<li><code>.kar</code></li>
<li><code>.cpt</code></li>
<li><code>.pit</code></li>
<li><code>.sit</code></li>
<li><code>.sea</code></li>
</ul>
<pre tabindex="0"><code class="language-none" data-lang="none">sEx x FileName.*                    # 解压
sEx a FileName.* FileName           # 压缩TEXT
</code></pre><h2 id="gzip">gzip</h2>
<p>减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。</p>
<p><code>gzip</code> 是在 Linux 系统中经常使用的压缩和解压缩的命令，既方便又好用。</p>
<p>语法：</p>
<pre tabindex="0"><code class="language-none" data-lang="none">gzip [选项] 压缩（解压缩）的文件名

-c 将输出写到标准输出上，并保留原有文件。
-d 将压缩文件解压。
-l 对每个压缩文件，显示下列字段：压缩文件的大小；未压缩文件的大小；压缩比；未压缩文件的名字
-r 递归式地查找指定目录并压缩其中的所有文件或者是解压缩。
-t 测试，检查压缩文件是否完整。
-v 对每一个压缩和解压的文件，显示文件名和压缩比。
-num 用指定的数字 num 调整压缩的速度，
-1 或 --fast 表示最快压缩方法（低压缩比），
-9 或--best表示最慢压缩方法（高压缩比）。系统缺省值为 6。TEXT
</code></pre><p>指令实例：</p>
<ul>
<li>
<p><code>gzip *%</code></p>
<p>把当前目录下的每个文件压缩成 <code>.gz</code> 文件。</p>
</li>
<li>
<p><code>gzip -dv *%</code></p>
<p>把当前目录下每个压缩的文件解压，并列出详细的信息。</p>
</li>
<li>
<p><code>gzip -l *%</code></p>
<p>详细显示每个压缩的文件的信息，并不解压。</p>
</li>
<li>
<p><code>gzip usr.tar%</code></p>
<p>压缩 <code>tar</code> 备份文件 <code>usr.tar</code> ，此时压缩文件的扩展名为 <code>.tar.gz</code> 。</p>
</li>
</ul>
<hr>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-js" data-lang="js"><span class="line"><span class="cl"><span class="err">├──</span> <span class="nx">publish</span><span class="o">/</span>
</span></span><span class="line"><span class="cl"><span class="err">└──</span> <span class="nx">src</span><span class="o">/</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="nx">assets</span><span class="o">/</span>                    <span class="c1">// 静态资源目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">common</span><span class="o">/</span>                    <span class="c1">// 通用类库目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">components</span><span class="o">/</span>                <span class="c1">// 公共组件目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">router</span><span class="o">/</span>                    <span class="c1">// 路由配置目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">store</span><span class="o">/</span>                     <span class="c1">// 状态管理目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">style</span><span class="o">/</span>                     <span class="c1">// 通用 CSS 目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">utils</span><span class="o">/</span>                     <span class="c1">// 工具函数目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">views</span><span class="o">/</span>                     <span class="c1">// 页面组件目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="err">├──</span> <span class="nx">App</span><span class="p">.</span><span class="nx">vue</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="nx">main</span><span class="p">.</span><span class="nx">ts</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="nx">shims</span><span class="o">-</span><span class="nx">vue</span><span class="p">.</span><span class="nx">d</span><span class="p">.</span><span class="nx">ts</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="nx">tests</span><span class="o">/</span>                         <span class="c1">// 单元测试目录
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="err">├──</span> <span class="nx">index</span><span class="p">.</span><span class="nx">html</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="nx">tsconfig</span><span class="p">.</span><span class="nx">json</span>                  <span class="c1">// TypeScript 配置文件
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="err">├──</span> <span class="nx">vite</span><span class="p">.</span><span class="nx">config</span><span class="p">.</span><span class="nx">ts</span>                 <span class="c1">// Vite 配置文件
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="err">└──</span> <span class="kr">package</span><span class="p">.</span><span class="nx">json</span>
</span></span></code></pre></td></tr></table>
</div>
</div><hr>
<pre tabindex="0"><code>[ 😅 ] ❤
你好呀 👋 我是皆非
Hi 👋 This is JieFei
99年的巨蟹座🦀，原通信工程📡，现主计算机方向💻
想着平时从事与计算机相关的工作，业余当一个游戏主播和实况玩家
喜欢打篮球🏀、画画✏️、玩游戏🎮
目光所至，心之所向，欢迎交♂朋友🤞😘
</code></pre><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 校验是否为空(null/空串)
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkNull</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">str</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span><span class="p">(</span><span class="nx">str</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">str</span> <span class="o">==</span> <span class="s2">&#34;&#34;</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 校验是否为纯数字
</span></span></span><span class="line"><span class="cl"><span class="cm"> * js的isNaN函数
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkNum</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">num</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span><span class="p">(</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">num</span><span class="p">)){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 校验是否为纯数字(正则)
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkNum2</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">num</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">     <span class="kd">var</span> <span class="nx">re</span> <span class="o">=</span> <span class="sr">/^[0-9]+.?[0-9]*$/</span><span class="p">;</span> <span class="c1">//判断字符串是否为数字 （判断正整数 /^[1-9]+[0-9]*]*$/）
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>     <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">re</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">num</span><span class="p">)){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">     <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验手机号
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkPhone</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">phone</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">reg</span> <span class="o">=</span> <span class="sr">/^1[3|4|5|7|8][0-9]{9}$/</span><span class="p">;</span> <span class="c1">//验证规则,第一位是【1】开头，第二位有【3,4,5,7,8】，第三位及以后可以是【0-9】
</span></span></span><span class="line"><span class="cl"><span class="c1">//  var reg = /^1[0-9]{10}$/;//不验证第二位，防止几年后新增号码段
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">reg</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">phone</span><span class="p">)){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 校验ip
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkIp</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">ip</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">reSpaceCheck</span> <span class="o">=</span> <span class="sr">/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">reSpaceCheck</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ip</span><span class="p">)){</span>
</span></span><span class="line"><span class="cl">        <span class="nx">ip</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">reSpaceCheck</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="p">(</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$1</span> <span class="o">&lt;=</span> <span class="mi">255</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$1</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$2</span> <span class="o">&lt;=</span> <span class="mi">255</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$2</span> <span class="o">&gt;=</span><span class="mi">0</span>
</span></span><span class="line"><span class="cl">          <span class="o">&amp;&amp;</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$3</span> <span class="o">&lt;=</span> <span class="mi">255</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$3</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$4</span> <span class="o">&lt;=</span> <span class="mi">255</span> <span class="o">&amp;&amp;</span> <span class="nb">RegExp</span><span class="p">.</span><span class="nx">$4</span><span class="o">&gt;=</span><span class="mi">0</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">            <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span><span class="k">else</span><span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span><span class="k">else</span><span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验url地址
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkUrl</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">url</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">reg</span> <span class="o">=</span> <span class="sr">/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">reg</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">url</span><span class="p">))</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/*
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验身份证
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkIdCard</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">idCard</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">aCity</span><span class="o">=</span><span class="p">{</span><span class="mi">11</span><span class="o">:</span><span class="s2">&#34;北京&#34;</span><span class="p">,</span><span class="mi">12</span><span class="o">:</span><span class="s2">&#34;天津&#34;</span><span class="p">,</span><span class="mi">13</span><span class="o">:</span><span class="s2">&#34;河北&#34;</span><span class="p">,</span><span class="mi">14</span><span class="o">:</span><span class="s2">&#34;山西&#34;</span><span class="p">,</span><span class="mi">15</span><span class="o">:</span><span class="s2">&#34;内蒙古&#34;</span><span class="p">,</span><span class="mi">21</span><span class="o">:</span><span class="s2">&#34;辽宁&#34;</span><span class="p">,</span><span class="mi">22</span><span class="o">:</span><span class="s2">&#34;吉林&#34;</span><span class="p">,</span><span class="mi">23</span><span class="o">:</span><span class="s2">&#34;黑龙江&#34;</span><span class="p">,</span><span class="mi">31</span><span class="o">:</span><span class="s2">&#34;上海&#34;</span><span class="p">,</span><span class="mi">32</span><span class="o">:</span><span class="s2">&#34;江苏&#34;</span><span class="p">,</span><span class="mi">33</span><span class="o">:</span><span class="s2">&#34;浙江&#34;</span><span class="p">,</span><span class="mi">34</span><span class="o">:</span><span class="s2">&#34;安徽&#34;</span><span class="p">,</span><span class="mi">35</span><span class="o">:</span><span class="s2">&#34;福建&#34;</span><span class="p">,</span><span class="mi">36</span><span class="o">:</span><span class="s2">&#34;江西&#34;</span><span class="p">,</span><span class="mi">37</span><span class="o">:</span><span class="s2">&#34;山东&#34;</span><span class="p">,</span><span class="mi">41</span><span class="o">:</span><span class="s2">&#34;河南&#34;</span><span class="p">,</span><span class="mi">42</span><span class="o">:</span><span class="s2">&#34;湖北&#34;</span><span class="p">,</span><span class="mi">43</span><span class="o">:</span><span class="s2">&#34;湖南&#34;</span><span class="p">,</span><span class="mi">44</span><span class="o">:</span><span class="s2">&#34;广东&#34;</span><span class="p">,</span><span class="mi">45</span><span class="o">:</span><span class="s2">&#34;广西&#34;</span><span class="p">,</span><span class="mi">46</span><span class="o">:</span><span class="s2">&#34;海南&#34;</span><span class="p">,</span><span class="mi">50</span><span class="o">:</span><span class="s2">&#34;重庆&#34;</span><span class="p">,</span><span class="mi">51</span><span class="o">:</span><span class="s2">&#34;四川&#34;</span><span class="p">,</span><span class="mi">52</span><span class="o">:</span><span class="s2">&#34;贵州&#34;</span><span class="p">,</span><span class="mi">53</span><span class="o">:</span><span class="s2">&#34;云南&#34;</span><span class="p">,</span><span class="mi">54</span><span class="o">:</span><span class="s2">&#34;西藏&#34;</span><span class="p">,</span><span class="mi">61</span><span class="o">:</span><span class="s2">&#34;陕西&#34;</span><span class="p">,</span><span class="mi">62</span><span class="o">:</span><span class="s2">&#34;甘肃&#34;</span><span class="p">,</span><span class="mi">63</span><span class="o">:</span><span class="s2">&#34;青海&#34;</span><span class="p">,</span><span class="mi">64</span><span class="o">:</span><span class="s2">&#34;宁夏&#34;</span><span class="p">,</span><span class="mi">65</span><span class="o">:</span><span class="s2">&#34;新疆&#34;</span><span class="p">,</span><span class="mi">71</span><span class="o">:</span><span class="s2">&#34;台湾&#34;</span><span class="p">,</span><span class="mi">81</span><span class="o">:</span><span class="s2">&#34;香港&#34;</span><span class="p">,</span><span class="mi">82</span><span class="o">:</span><span class="s2">&#34;澳门&#34;</span><span class="p">,</span><span class="mi">91</span><span class="o">:</span><span class="s2">&#34;国外&#34;</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">iSum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">info</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="sr">/^\d{17}(\d|x)$/i</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">idCard</span><span class="p">)){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span><span class="c1">//身份证长度或格式错误
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="nx">idCard</span> <span class="o">=</span> <span class="nx">idCard</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/x$/i</span><span class="p">,</span> <span class="s2">&#34;a&#34;</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">aCity</span><span class="p">[</span><span class="nb">parseInt</span><span class="p">(</span><span class="nx">idCard</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">))]</span> <span class="o">==</span> <span class="kc">null</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span><span class="c1">//身份证地区非法;
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">sBirthday</span> <span class="o">=</span> <span class="nx">idCard</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&#34;-&#34;</span> <span class="o">+</span> <span class="nb">Number</span><span class="p">(</span><span class="nx">idCard</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> <span class="o">+</span> <span class="s2">&#34;-&#34;</span> <span class="o">+</span> <span class="nb">Number</span><span class="p">(</span><span class="nx">idCard</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">2</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">d</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">sBirthday</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/-/g</span><span class="p">,</span> <span class="s2">&#34;/&#34;</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">sBirthday</span> <span class="o">!=</span> <span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getFullYear</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&#34;-&#34;</span> <span class="o">+</span> <span class="p">(</span><span class="nx">d</span><span class="p">.</span><span class="nx">getMonth</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&#34;-&#34;</span> <span class="o">+</span> <span class="nx">d</span><span class="p">.</span><span class="nx">getDate</span><span class="p">())){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span><span class="c1">//身份证上的出生日期非法;
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">17</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span><span class="o">--</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">        <span class="nx">iSum</span> <span class="o">+=</span> <span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">%</span> <span class="mi">11</span><span class="p">)</span> <span class="o">*</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">idCard</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">17</span> <span class="o">-</span> <span class="nx">i</span><span class="p">),</span> <span class="mi">11</span><span class="p">);</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">iSum</span> <span class="o">%</span> <span class="mi">11</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">){</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span><span class="c1">//身份证号非法;
</span></span></span><span class="line"><span class="cl"><span class="c1"></span>    <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/* 
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验邮箱 
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>  
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkEmail</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">emailStr</span><span class="p">){</span>  
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">reg</span> <span class="o">=</span> <span class="sr">/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/</span><span class="p">;</span>   
</span></span><span class="line"><span class="cl">    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">reg</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">emailStr</span><span class="p">)){</span>  
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl">    <span class="p">}</span>  
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/* 
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验日期 
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 格式为YYYY-MM-DD 
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>  
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkDate</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">dateValue</span><span class="p">)</span> <span class="p">{</span>  
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">dateValue</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/</span><span class="p">);</span>  
</span></span><span class="line"><span class="cl">    <span class="k">if</span> <span class="p">(</span><span class="nx">result</span> <span class="o">==</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>  
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl">    <span class="p">}</span>  
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl"><span class="p">}</span> 
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-javascript" data-lang="javascript"><span class="line"><span class="cl"><span class="cm">/* 
</span></span></span><span class="line"><span class="cl"><span class="cm"> * 检验否是汉字  
</span></span></span><span class="line"><span class="cl"><span class="cm"> */</span>  
</span></span><span class="line"><span class="cl"><span class="kd">var</span> <span class="nx">checkCharacter</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">charValue</span><span class="p">)</span> <span class="p">{</span>  
</span></span><span class="line"><span class="cl">    <span class="kd">var</span> <span class="nx">reg</span> <span class="o">=</span> <span class="sr">/^[\u4e00-\u9fa5]{0,}$/</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl">    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">reg</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">charValue</span><span class="p">)){</span>  
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl">    <span class="p">}</span>  
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>  
</span></span><span class="line"><span class="cl"><span class="p">}</span> 
</span></span></code></pre></td></tr></table>
</div>
</div>
	</article>
</main>





	

	

	



  <footer class="mt-8 flex sm:flex-col-reverse justify-between items-center">
  <p class="mt-0 text-sm">
    © 2022 | 橘子
    
  </p>
  <p class="flex items-center mt-0">
    
  </p>
</footer>
</body>
</html>